// MaskEditDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MaskEditDemo.h"
#include "MaskEditDemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	void UpdateFont();
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CCJHyperLink	m_staticEmail;
	CCJHyperLink	m_staticAddress;
	CStatic     	m_staticDisclaimer;
	CString			m_editDisclaimer;
	//}}AFX_DATA

	CFont	m_Font;
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_editDisclaimer = _T("");
	//}}AFX_DATA_INIT

	m_editDisclaimer.LoadString(IDS_DISCLAIMER);
	UpdateFont();
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_STATIC_MAILME, m_staticEmail);
	DDX_Control(pDX, IDC_STATIC_DISCLAIMER, m_staticDisclaimer);
	DDX_Control(pDX, IDC_STATIC_ADDRESS, m_staticAddress);
	DDX_Text(pDX, IDC_EDIT_DISCLAIMER, m_editDisclaimer);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CAboutDlg::UpdateFont()
{
	NONCLIENTMETRICS ncm;
	memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
	ncm.cbSize = sizeof(NONCLIENTMETRICS);
	VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
		sizeof(NONCLIENTMETRICS), &ncm, 0));
	ncm.lfMessageFont.lfWeight = 700;
	m_Font.CreateFontIndirect(&ncm.lfMessageFont);
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// set the hyperlinks and static font.
	m_staticEmail.SetURL(_T("mailto:kstowell@codejockeys.com"));
	m_staticAddress.SetURL(_T("http://www.codejockeys.com/kstowell/"));
	m_staticDisclaimer.SetFont(&m_Font);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
// CMaskEditDemoDlg dialog

CMaskEditDemoDlg::CMaskEditDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMaskEditDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMaskEditDemoDlg)
	m_nMaxHours = 23;
	m_nMaxMins = 59;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMaskEditDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMaskEditDemoDlg)
	DDX_Control(pDX, IDC_EDIT_MAX_MINS, m_MaxMins);
	DDX_Control(pDX, IDC_EDIT_MAX_HOURS, m_MaxHours);
	DDX_Control(pDX, IDC_EDIT_ZIPCODE, m_ZipEdit);
	DDX_Control(pDX, IDC_EDIT_TIME, m_TimeEdit);
	DDX_Control(pDX, IDC_EDIT_TELEPHONE, m_TelephoneEdit);
	DDX_Control(pDX, IDC_EDIT_DATE, m_DateEdit);
	DDX_Control(pDX, IDC_EDIT_HEX, m_HexEdit);
	DDX_Control(pDX, IDC_EDIT_IPADDRESS, m_IPAddressEdit);
	DDX_Text(pDX, IDC_EDIT_MAX_HOURS, m_nMaxHours);
	DDX_Text(pDX, IDC_EDIT_MAX_MINS, m_nMaxMins);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMaskEditDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CMaskEditDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT_MAX_HOURS, OnChangeEditMaxHours)
	ON_EN_CHANGE(IDC_EDIT_MAX_MINS, OnChangeEditMaxMins)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMaskEditDemoDlg message handlers

BOOL CMaskEditDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	// CCJTimeEdit
	m_TimeEdit.SetDateTime(COleDateTime::GetCurrentTime());
	// CCJTimeEdit
	m_DateEdit.SetDateTime(COleDateTime::GetCurrentTime());
	
	// CCJMaskEdit - define the masked used by the controls. The first arg is the actual mask,
	// the second arg is literal, that is where the '_' appears is where the user
	// will be allowed to enter data, the third arg is the default window text.

	m_IPAddressEdit.SetEditMask	(_T("999.999.999.999"), _T("___.___.___.___"), _T("209.66 .99 .126"));
	m_TelephoneEdit.SetEditMask	(_T("(000) 000-0000"),  _T("(___) ___-____"),  _T("(800) 555-1212"));
	m_ZipEdit.SetEditMask		(_T("00000-0000"),      _T("_____-____"),	   _T("12345-1234"));
	m_HexEdit.SetEditMask		(_T("0xHHHHHHHH"),      _T("0x________"),      _T("0x00000000"));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMaskEditDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMaskEditDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMaskEditDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMaskEditDemoDlg::OnChangeEditMaxHours() 
{
	UpdateData();
	m_TimeEdit.SetHours(m_nMaxHours);
}

void CMaskEditDemoDlg::OnChangeEditMaxMins() 
{
	UpdateData();
	m_TimeEdit.SetMins(m_nMaxMins);
}
